﻿using System;

using System.Collections;
using System.Collections.Generic;

using System.Data;
using System.Data.Common;

using System.Linq;

using System.Net.Mail;

using System.Runtime.Serialization;

using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;

using Microsoft.Practices.EnterpriseLibrary;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;

using nms.gaming.model;

namespace nms.gaming.webservice
{
    /// <summary>
    /// </summary>
    [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class ExchangeRate : IExchangeRateService
    {
        /// <summary>
        /// </summary>
        /// <param name="source"></param>
        /// <param name="destination"></param>
        /// <returns></returns>
        public nms.gaming.model.ExchangeRate[] ExchangeRateQuery( string source , string destination )
        {
            /// --
            Database _db = DatabaseFactory.CreateDatabase();
            /// -- 
            IRowMapper<nms.gaming.model.ExchangeRate> rowMapper = MapBuilder<nms.gaming.model.ExchangeRate>
                .MapAllProperties()
                .Map(b => b.Source).ToColumn("SRC_CURRENCY_SYMBOL")
                .Map(b => b.Destination).ToColumn("DST_CURRENCY_SYMBOL")
                .Map(b => b.Rate).ToColumn("EXCHANGE_RATE")
                .Build();

            IEnumerable<nms.gaming.model.ExchangeRate> _exchangeRates = _db.ExecuteSprocAccessor<nms.gaming.model.ExchangeRate>("sp_ExchangeRate", rowMapper, source, destination );
            return _exchangeRates.ToArray<nms.gaming.model.ExchangeRate>();  
        }

        /// <summary>
        /// </summary>
        /// <param name="source"></param>
        /// <param name="destination"></param>
        /// <returns></returns>
        public nms.gaming.model.ExchangeRate[] ExchangeRateQueryJSON(string source, string destination)
        { return ExchangeRateQuery(source, destination); }

        /// <summary>
        /// </summary>
        /// <param name="source"></param>
        /// <param name="destination"></param>
        /// <returns></returns>
        public nms.gaming.model.ExchangeRate[] ExchangeRateQueryJSON_EXPLICIT(string source, string destination)
        { return ExchangeRateQuery( source, destination ); }

        /// <summary>
        /// </summary>
        /// <param name="source"></param>
        /// <param name="destination"></param>
        /// <param name="rate"></param>
        /// <returns></returns>
        public nms.gaming.model.ExchangeRate[] ExchangeRateUpdate(string source, string destination, string rate)
        {
            /// --
            Database _db = DatabaseFactory.CreateDatabase();
            /// -- 
            IRowMapper<nms.gaming.model.ExchangeRate> rowMapper = MapBuilder<nms.gaming.model.ExchangeRate>
                .MapAllProperties()
                .Map(b => b.Source).ToColumn("SRC_CURRENCY_SYMBOL")
                .Map(b => b.Destination).ToColumn("DST_CURRENCY_SYMBOL")
                .Map(b => b.Rate).ToColumn("EXCHANGE_RATE")
                .Build();

            IEnumerable<nms.gaming.model.ExchangeRate> _exchangeRates = _db.ExecuteSprocAccessor<nms.gaming.model.ExchangeRate>("sp_ExchangeRateUpdate", rowMapper, source, destination, rate);

            /// --
            return _exchangeRates.ToArray<nms.gaming.model.ExchangeRate>();   
        }

        /// <summary>
        /// </summary>
        /// <param name="source"></param>
        /// <param name="destination"></param>
        /// <param name="rate"></param>
        /// <returns></returns>
        public nms.gaming.model.ExchangeRate[] ExchangeRateUpdateJSON(string source, string destination, string rate)
        { return ExchangeRateUpdate(source, destination, rate); }

        /// <summary>
        /// </summary>
        /// <param name="source"></param>
        /// <param name="destination"></param>
        /// <param name="rate"></param>
        /// <returns></returns>
        public nms.gaming.model.ExchangeRate[] ExchangeRateUpdateJSON_EXPLICIT(string source, string destination, string rate)
        { return ExchangeRateUpdate(source, destination, rate); }
    }
}
